package com.ruoyi.web.controller.system;

import java.io.IOException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.ruoyi.common.core.domain.entity.SysUser;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.BiogasDispatchingData;
import com.ruoyi.system.service.IBiogasDispatchingDataService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;
import org.springframework.web.multipart.MultipartFile;

/**
 * 【请填写功能名称】Controller
 * 
 * @author ruoyi
 * @date 2020-09-25
 */
@RestController
@RequestMapping("/system/data")
public class BiogasDispatchingDataController extends BaseController
{
    @Autowired
    private IBiogasDispatchingDataService biogasDispatchingDataService;

    /**
     * 查询【请填写功能名称】列表
     */
    @PreAuthorize("@ss.hasPermi('system:data:list')")
    @GetMapping("/list")
    public TableDataInfo list(BiogasDispatchingData biogasDispatchingData)
    {
        startPage();
        List<BiogasDispatchingData> list = biogasDispatchingDataService.selectBiogasDispatchingDataList(biogasDispatchingData);
        return getDataTable(list);
    }

    /**
     * 导出【请填写功能名称】列表
     */
    @PreAuthorize("@ss.hasPermi('system:data:export')")
    @Log(title = "【请填写功能名称】", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(BiogasDispatchingData biogasDispatchingData)
    {
        List<BiogasDispatchingData> list = biogasDispatchingDataService.selectBiogasDispatchingDataList(biogasDispatchingData);
        ExcelUtil<BiogasDispatchingData> util = new ExcelUtil<BiogasDispatchingData>(BiogasDispatchingData.class);
        return util.exportExcel(list, "data");
    }

    /**
     * 获取【请填写功能名称】详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:data:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(biogasDispatchingDataService.selectBiogasDispatchingDataById(id));
    }

    /**
     * 新增【请填写功能名称】
     */
    @PreAuthorize("@ss.hasPermi('system:data:add')")
    @Log(title = "【请填写功能名称】", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BiogasDispatchingData biogasDispatchingData)
    {
        return toAjax(biogasDispatchingDataService.insertBiogasDispatchingData(biogasDispatchingData));
    }

    /**
     * 修改【请填写功能名称】
     */
    @PreAuthorize("@ss.hasPermi('system:data:edit')")
    @Log(title = "【请填写功能名称】", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BiogasDispatchingData biogasDispatchingData)
    {
        return toAjax(biogasDispatchingDataService.updateBiogasDispatchingData(biogasDispatchingData));
    }

    /**
     * 删除【请填写功能名称】
     */
    @PreAuthorize("@ss.hasPermi('system:data:remove')")
    @Log(title = "【请填写功能名称】", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(biogasDispatchingDataService.deleteBiogasDispatchingDataByIds(ids));
    }


    /**
     * 删除【请填写功能名称】
     */
    @PreAuthorize("@ss.hasPermi('system:data:importExcel')")
    @Log(title = "【请填写功能名称】", businessType = BusinessType.DELETE)
    @PostMapping("/importExcel")
    public AjaxResult importExcel(@RequestParam("file") MultipartFile file) throws Exception {
        String fileName = file.getOriginalFilename();
        biogasDispatchingDataService.handleImportExcel(fileName,file.getInputStream());
        return null;
    }

    @GetMapping("/importTemplate")
    public AjaxResult importTemplate()
    {
        ExcelUtil<BiogasDispatchingData> util = new ExcelUtil<BiogasDispatchingData>(BiogasDispatchingData.class);
        return util.importTemplateExcel("沼气导入");
    }
}
